package cn.flying.cloud.message.core.sender.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lmax.disruptor.EventHandler;

import cn.flying.cloud.message.core.sender.event.MessageEvent;
import cn.flying.cloud.message.core.strategy.MessageSenderStrategy;
import cn.flying.cloud.message.model.MessageRequest;

/**
 * 消息通知类事件处理器
 *
 * @author: admin
 * @date: 2025年03月18日 11:05
 * @version: 1.0
 */
public class MessageEventHandler implements EventHandler<MessageEvent> {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * @param event
     * @param sequence
     * @param endOfBatch
     * @throws Exception
     */
    @Override
    public void onEvent(MessageEvent event, long sequence, boolean endOfBatch) throws Exception {
        MessageRequest request = event.getRequest();
        logger.info("下发消息：【{}】", event);
        try {
            MessageSenderStrategy senderStrategy = event.getMessageSenderStrategy();
            senderStrategy.sender(request, event.getStorage(), event.getSendType(), event.isHtml());
        } catch (Exception e) {
            logger.error("下发消息异常！{}", e.getMessage());
        }
    }
}
